home *** CD-ROM | disk | FTP | other *** search
/ Czech Logic, Card & Gambling Games / Logické hry.iso / hry / Fish Fillets / script / share / prog_save.lua < prev    next >
Encoding:
Text File  |  2005-07-16  |  1.2 KB  |  41 lines

  1. -- -----------------------------------------------------------------
  2. -- These function are called when save or load is made.
  3. -- script_save() ... calls level_save(serialized_level)
  4. -- script_load() ... calls level_load(saved_moves)
  5. --                   with global variable saved_moves
  6. -- script_loadState() ... uses global variable saved_models
  7. --                        to restore model states
  8. -- -----------------------------------------------------------------
  9.  
  10. file_include("script/share/Pickle.lua")
  11.  
  12. function script_save()
  13.     local serialized = pickle(getModelsTable())
  14.     level_save(serialized)
  15. end
  16.  
  17. function script_load()
  18.     if not saved_moves then
  19.         error("global variable 'saved_moves' is not set")
  20.     end
  21.     level_load(saved_moves)
  22. end
  23.  
  24. function script_loadState()
  25.     if not saved_models then
  26.         error("global variable 'saved_models' is not set")
  27.     end
  28.     local models = getModelsTable()
  29.     local saved_table = unpickle_table(saved_models)
  30.  
  31.     --NOTE: don't save objects with cross references
  32.     --NOTE: objects address will be different after load
  33.     for model_key, model in pairs(saved_table) do
  34.         for param_key, param in pairs(model) do
  35.             models[model_key][param_key] = param
  36.         end
  37.     end
  38. end
  39.  
  40.  
  41.